﻿using System;

namespace Permutations
{
    class Permutations
    {
        static void Print(int[] array)
        {
            foreach (int number in array)
            {
                Console.Write("{0} ", number + 1);
            }
            Console.WriteLine();
        }

        static void Permutation(int[] array, bool[] used, int i, int n)
        {
            if (i >= n)
            {
                Print(array);
                return;
            }
            for (int k = 0; k < n; k++)
            {
                if (!used[k])
                {
                    used[k] = true;
                    array[i] = k;
                    Permutation(array, used, i + 1, n);
                    used[k] = false;
                }
            }
        }

        static void Main()
        {
            Console.Write("Enter an integer for N: ");
            int n = int.Parse(Console.ReadLine());
            int[] array = new int[n];
            bool[] used = new bool[n];
            Permutation(array, used, 0, n);
        }
    }
}
